#include "conversionpallet.hpp"
#include <iostream>

ConversionPallet::ConversionPallet(){

    Glib::RefPtr<Gnome::Glade::Xml> Widgetstree = Gnome::Glade::Xml::create("interface4.glade");

    Widgetstree->get_widget("conversionpallet", window);

    Widgetstree->get_widget("radiobutton1", radio1);
    Widgetstree->get_widget("radiobutton2", radio2);
    Widgetstree->get_widget("radiobutton3", radio3);
    Widgetstree->get_widget("radiobutton4", radio4);
    Widgetstree->get_widget("radiobutton5", radio5);
    Widgetstree->get_widget("radiobutton6", radio6);
    Widgetstree->get_widget("radiobutton7", radio7);
    Widgetstree->get_widget("radiobutton8", radio8);
    Widgetstree->get_widget("radiobutton9", radio9);
    Widgetstree->get_widget("radiobutton10", radio10);
    Widgetstree->get_widget("radiobutton11", radio11);
    Widgetstree->get_widget("radiobutton12", radio12);
    Widgetstree->get_widget("radiobutton13", radio13);
    Widgetstree->get_widget("radiobutton14", radio14);
    Widgetstree->get_widget("radiobutton15", radio15);
    Widgetstree->get_widget("radiobutton16", radio16);
    Widgetstree->get_widget("radiobutton17", radio17);
    Widgetstree->get_widget("radiobutton18", radio18);
    Widgetstree->get_widget("radiobutton19", radio19);
    Widgetstree->get_widget("radiobutton20", radio20);
    Widgetstree->get_widget("radiobutton21", radio21);
    Widgetstree->get_widget("spinbutton1", value);

    radio1->set_active(true);
    radio3->set_active(true);
    radio5->set_active(true);
    radio7->set_active(true);
    radio9->set_active(true);
    radio12->set_active(true);
    radio14->set_active(true);
    radio18->set_active(true);

    radio1->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio2->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio3->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio4->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio5->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio6->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio7->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio8->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio9->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio10->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio11->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio12->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio13->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio14->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio15->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio16->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio17->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio18->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio19->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio20->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    radio21->signal_clicked().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));
    value->signal_value_changed().connect(sigc::mem_fun(*this, &ConversionPallet::paramchange));

    binaryto=1;
    greyto=1;
    colorto=1;
    binarytogreyoption=0;
    binarytocoloroption=0;
    greytobinaryoption=0;
    greytocoloroption=0;
    colortobinaryoption=0;
    colortograyoption=0;

    window->show_all();

}

Gtk::Window* ConversionPallet::getWindow(){
    return window;
}


void ConversionPallet::readParams(){
    if(radio1->get_active())
        binaryto=1;
    else
        binaryto=2;

    if(radio3->get_active())
        greyto=1;
    else
        greyto=2;

    if(radio5->get_active())
        colorto=1;
    else
        colorto=2;

    if(radio7->get_active())
        binarytogreyoption=0;
    else
        binarytogreyoption=1;

    if(radio9->get_active())
        greytobinaryoption=0;
    else if(radio10->get_active())
        greytobinaryoption=1;
    else
        greytobinaryoption=2;

    if(radio12->get_active())
        greytocoloroption=0;
    else
        greytocoloroption=1;

    if(radio14->get_active())
        colortobinaryoption=0;
    else if(radio16->get_active())
        colortobinaryoption=1;
    else if(radio15->get_active())
        colortobinaryoption=2;
    else
        colortobinaryoption=3;

    if(radio18->get_active())
        colortograyoption=0;
    else if(radio20->get_active())
        colortograyoption=1;
    else if(radio19->get_active())
        colortograyoption=2;
    else
        colortograyoption=3;

    setedvalue=value->get_value_as_int();

}

void ConversionPallet::paramchange(){
    readParams();
}
